package com.rychlickikicior.kitijdb;

/**
 * This class represents the general primary key of the entity.
 * @author kitikat
 */
public class PrimaryKey {
    private Object[] key;

    /**
     * Creates the primary key object based on given values.
     * @param key Elements of the primary key.
     */
    public PrimaryKey(Object ... key) {
        this.key = key;
    }
   /**
     * Creates the primary key object based on single integer value.
     * @param key Single, integer value of the primary key, for the simplest tables.
     */
    public PrimaryKey(int part) {
        this.key = new Object[] { part };
    }

    /**
     * Returns elements of the primary key.
     * @return Elements of the primary key.
     */
    public Object[] getKey() {
        return key;
    }
    /**
     * Sets elements of the primary key.
     * @param val Elements of the primary key.
     */
    public void setKey(Object ... val) {
        this.key = val;
    }

    /**
     * Returns value of the primary key as a single integer.
     * @return Value of the primary key.
     */
    public int getID() {
        if (key != null && key.length >= 1)
            return Integer.parseInt(key[0].toString());
        else
            return -1;
    }

     /**
     * Sets the value of the primary key to the single integer.
     * @param New integer value of the primary key.
     */
    public void setID(int id) {
        this.key = new Object[] { id } ;
    }
}
